package org.example.campus_sys_backend.mapper;

import org.apache.ibatis.annotations.*;
import org.example.campus_sys_backend.model.ActivityInfo;

import java.util.Date;
import java.util.List;

@Mapper
public interface ActivityInfoMapper {

    @Insert("insert into activity (name, category, title, creator, abs, detailed_desc, " +
            "status, created_time, archived_time, " +
            "pic_urls, start_time, end_time) values (#{name}, #{category}, #{title}, " +
            "#{creator}, #{abs}, #{detailedDesc}, #{status}, #{createdTime}, #{archivedTime}, #{picUrls}, #{startTime}, #{endTime} ) ")
    Integer insertActivity(ActivityInfo activityInfo);

    @Update("update activity set name = #{name}, category = #{category}, title = #{title}, creator = #{creator}, abs = #{abs}, " +
           "detailed_desc = #{detailedDesc}, status = #{status}, created_time = #{createdTime}, archived_time = #{archivedTime}," +
            "pic_urls = #{picUrls}, start_time = #{startTime}, end_time = #{endTime} where id = #{id}")
    Integer updateActivity(@Param("id") Integer id,@Param("name") String name,@Param("category") String category,@Param("title") String title,@Param("creator") String creator,@Param("abs") String abs,
                          @Param("detailedDesc") String detailedDesc,@Param("status") String status,@Param("createdTime") Date createdTime,@Param("archivedTime") Date archivedTime,
                           @Param("picUrls") String picUrls,@Param("startTime") Date startTime,@Param("endTime") Date endTime);



    @Select("select name, category, title, creator, abs, detailed_desc," +
            "  status, created_time, archived_time, pic_urls, start_time, end_time from activity where id = #{id}")
    ActivityInfo queryActivityById(Integer id);
    @Select("select * from activity where (status = #{status} or #{status} is null)" +
            "          and name like CONCAT('%', #{name}, '%') order by created_time  desc")
    List<ActivityInfo> selectActivity(@Param("status") String status,@Param("name") String name);
   @Update("update activity set status = #{status}")
    Integer openActivity(@Param("id") Integer id,@Param("status") String status);
}
